package websocket

import (
	"common/global"
	"common/pkg"
	"errors"
)

// Authenticate validates the token and returns the user ID.
func Authenticate(tokenString string) (uint, error) {
	if tokenString == "" {
		return 0, errors.New("token is missing")
	}
	j := pkg.NewJWT(global.JwtSecretKey)
	claims, err := j.ParseToken(tokenString)
	if err != nil {
		return 0, err
	}
	userID := claims.ID
	return userID, nil
}
